package net.bwie.zg6.function.udf;

import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;

/**
 * 自定义UDF函数，将字符串中单词转换为小写: HELLO，输出：hello
 * @author xuanyu
 */
@Description(name = "string_lower",
	value = "_FUNC_(a) - Returns str with all characters changed to lowercase.")
public class StringLowerUDF extends UDF {

	/**
	 * 定义evaluate方法，实现数据处理
	 */
	public String evaluate (final String str) {
		if (str == null) {
			return null;
		}

		return str.toLowerCase();
	}

}


/*
-- 创建函数
CREATE FUNCTION lower_string AS 'net.bwie.zg6.function.udf.StringLowerUDF'
    USING JAR 'hdfs://node101:8020/user/hive/jars/hive-sql-udf.jar';

-- 测试函数
SELECT ename, lower_string(ename) AS name FROM db_hive.emp ;

 */